/** 
 * All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
 * 
 *MpmProjectCommunicationController
 * 项目沟通
 * 
 * 修改纪录
 * 2021-08-20 版本：1.0 liuchenguang 创建。
 * @version 版本：1.0
 * @author 作者：liuchenguang
 * 创建日期：2021-08-20
 */

package com.topscomm.mpm.controller;

import com.topscomm.basic.util.SQLAdapter;
import com.topscomm.mpm.service.impl.MpmProjectCommunicationService;
import java.util.List;
import java.util.Map;

import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topscomm.mpm.controller.auto.MpmProjectCommunicationControllerAuto;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: liuchenguang
 * @date: 2021-08-20
 * @description:项目沟通Controller
 * @modify:
 */
@RestController
@RequestMapping("mpm/projectCommunication")
public class MpmProjectCommunicationController extends MpmProjectCommunicationControllerAuto implements IMpmProjectCommunicationController {
	@Autowired
	public MpmProjectCommunicationService mpmProjectCommunicationService;

	/**
	 * @author: liuchenguang
	 * @date: 2021-08-20
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and name like '%{0}%' ", value);
		}
		if (paraMap.containsKey("qry_meetstyle")) {
			String value = paraMap.get("qry_meetstyle").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and meetstyle = '{0}' ", value);
			}
		}
		if (paraMap.containsKey("qry_begintime")) {
			String value = paraMap.get("qry_begintime").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and begintime >= {0} ", SQLAdapter.toDateLong(value + " 00:00:00"));
		}
		if (paraMap.containsKey("qry_endtime")) {
			String value = paraMap.get("qry_endtime").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and begintime <= {0}", SQLAdapter.toDateLong(value + " 23:59:59"));
		}
		if (paraMap.containsKey("qry_projectcode")) {
			String value = paraMap.get("qry_projectcode").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and projectcode = '{0}' ", value);
			}
		}
		if (paraMap.containsKey("qry_enabled")) {
			String value = paraMap.get("qry_enabled").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and enabled = '{0}' ", value);
			}
		}
		return sql.toString();
	}

	/**
	 * @author: liuchenguang
	 * @date: 2021-08-20
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}

	/**
	 * @param paraMap
	 * @return ResponseResult<Object>
	 * @author: liuchenguang
	 * @date: 2021-08-23
	 * @description:重写获取沟通列表
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/list")
	public ResponseResult<Object> list(
		@RequestParam(required = false) Map<String, Object> paraMap) {
		try {
			String sqlWhere = this.spellListSql(paraMap);
			return mpmProjectCommunicationService.communicationList(paraMap, sqlWhere);
		} catch (Exception ex) {
			return handleControllerException(ex);
		}
	}
}

